import java.util.ArrayList;
import java.util.List;

// 16695334890
public class P43 {
	private final static int[] PRIME = new int[] {2, 3, 5, 7, 11, 13, 17};
	
	public static void getPermutationList(List<Long> list, String num, String result) {
		
		//System.out.println(result);
		
		if (result.equals("1406357289")) {
			System.out.println(">>>>>>>>>>>>");
		}
		
		if (num.length() == 0) {
			long x = Long.parseLong(result);
			
			boolean isOK = true;
			for (int i = 2; i <= 8; i++) {
				if (result.equals("1406357289")) {
					System.out.println(result.substring(i - 1, i + 2));
				}
				
				if (Integer.parseInt(result.substring(i - 1, i + 2))%PRIME[i-2] != 0) {
					isOK = false;
					break;					
				}
			}
			
			if (isOK) {
				list.add(x);
			}
			return;
		}
		
		
		for (int i = 0; i < num.length(); i++) {
			String n = num.substring(i, i + 1);
			//System.out.println("*" + n + ":" + num + ":" + result);
			if (!result.contains(n)) {
				getPermutationList(list, num.replaceAll(n, ""), result + n);
			}
		}		
	}

	public static void main(String[] args) {
		//3628800
		//4757760
		List<Long> list = new ArrayList<Long>(0);
		
		getPermutationList(list, "0123456789", "");
		
		long sum = 0;
		
		System.out.println();
		for(Long l : list) {
			sum += l;
			System.out.println(l);
		}
		
		System.out.println();
		System.out.println(list.size());
		System.out.println();
		System.out.println(sum);
	}
}
